package com.woniu.controller;

import com.woniu.pojo.Student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@Slf4j
@RequestMapping("portal")
public class portalController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private Student student;
    private static final String URL = "http://CINEMA-MEMBER/member/";

    @GetMapping("/{mid}")
    public String findMemberById(@PathVariable("mid")Integer mid){

        String url = URL+"/"+mid;

        String forObject = restTemplate.getForObject(url, String.class);

        return "success"+forObject;

    }

    @GetMapping("/put/{mid}")
    public void updateStu(@PathVariable("mid")Integer mid){
        String url = URL+"/"+mid;
        student.setAge(111111);
        student.setName("aaaaaaaaaaaa");
        restTemplate.put(url,student);
    }

    @GetMapping("/post/{mid}")
    public void insertStu(@PathVariable("mid")Integer mid){
        String url = URL+"/"+mid;
        student.setAge(11444411);
        student.setName("aaaxxxxxaaaaaa");
        restTemplate.postForEntity(url,student,Student.class);
    }

    @GetMapping("/delete/{mid}")
    public void deleteStu(@PathVariable("mid")Integer mid){
        String url = URL+"/"+mid;
        restTemplate.delete(url);
    }

}
